package com.tongcao.cn.algorithm.designMoel.obsever;

import org.assertj.core.util.Lists;

import java.util.List;

/**
 * @Author:tongcao
 * @Date:2019/4/11 15:20
 * Description:接下来3D服务号的实现类
 */
public class ObserverFor3D extends AbstrctSubject {


    private List<Observer> observers = Lists.newArrayList();

    /**
     * 3D 彩票的号码
     */
    private String msg;

    @Override
    public void registerObserver(Observer observer) {
        if (observer != null) {
            observers.add(observer);
        }
    }


    @Override
    public void removeObServer(Observer observer) {
        if (observer != null) {
            observers.remove(observer);
        }
    }

    @Override
    public void notifyAllObservers() {
        for (Observer observer : observers) {
            observer.update(msg);
        }
        cleanMsg();

    }

    /**
     * 主题更新信息
     */
    public void setMsg(String msg) {
        this.msg = msg;
        notifyAllObservers();
    }

    @Override
    public void cleanMsg() {
        this.msg = "";
    }
}